package com.lin.pay.paypal.v2;

import com.lin.config.PropertyUtil;
import com.lin.config.SpringContextIniter;
import com.paypal.core.PayPalEnvironment;
import com.paypal.core.PayPalHttpClient;
import com.paypal.http.HttpClient;

public class Harness {
    private Harness() {
    }

    public static enum HarnessEnum {
        SINGLETON;
        private HttpClient client = null;

        private HarnessEnum() {
            //String profile = SpringContextIniter.getActiveProfile();
            String profile = "test";
            PayPalEnvironment environment = null;
            if ("dev".equals(profile)) {
                environment = new PayPalEnvironment.Sandbox(
                        System.getenv(PropertyUtil.getString("cs.pay.paypal.client-id")),
                        System.getenv(PropertyUtil.getString("cs.pay.paypal.client-secret")));
            } else if ("pro".equals(profile)) {
                environment = new PayPalEnvironment.Live(
                        System.getenv(PropertyUtil.getString("cs.pay.paypal.client-id")),
                        System.getenv(PropertyUtil.getString("cs.pay.paypal.client-secret")));
            }else{
                environment = new PayPalEnvironment.Live(
                        System.getenv("AZib_e-Xfb0VvWhLkUrFcYEkTkOCiofHuS0NwTOViD51I3GVKyyx3wg3XDb9Ubn6NJBvE-awgjNU0lZ-"),
                        System.getenv("EGcVxcChgaGaB4b8-aAZy5uN7gDA-53cK0sscSJJBOlT19xdqHt8gVnjuOjYM1HhcyAdOZJnqcZeHHhM"));
            }
            client = new PayPalHttpClient(environment);
        }

        public HttpClient getInstance() {
            System.out.println("public HttpClient getInstance()");
            return client;
        }
    }

    public static void main(String[] args) {
        System.out.println(HarnessEnum.SINGLETON.getInstance());
    }
}
